<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<%@ include file="/include/taglibs.jsp"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page isELIgnored="false" %>
<head>
	<title>模块管理</title>
	<link rel="stylesheet" href="${ctx}/assets/admin/LingUI/css/ui.jqgrid.css" />
</head>

<div class="row">
	<div class="col-xs-12">
		<div id="search"></div>											<%--查询条件更多 --%>
		<div class="b_grid_line  col-lg-12"></div>						<!-- 分隔线 -->
		<table id="module_list_table" class="grid-table"></table> 	<%--jqgrid数据表格 --%>
		<div id="module_list_pager"></div>							<%--jqgrid表格 页脚 --%>
	</div>
</div>
<script type="text/javascript">
	var scripts = [null,
		"${ctx}/assets/admin/LingUI/js/jqGrid/jquery.jqGrid.js",
		"${ctx}/assets/admin/LingUI/js/jqGrid/i18n/grid.locale-cn.js",
		"${ctx}/assets/admin/LingUI/js/control.js",
		"${ctx}/assets/admin/LingUI/js/jsutil/js/jquery.filterSearch.js",   //筛选搜索
		null];
	var _grid_id = "#module_list_table";	//表格 选择器
	var _pager_id = "#module_list_pager";	//表格页脚 选择器
	ace.load_ajax_scripts(scripts, function() {
		$("#search").strongFilterSearch({
			inputFiled:"MODULE_NAME",				//搜索字段，不填默认为searchValue
			inputPlaceholder:"请输入模块名称等关键字",		//占位符
			searchCallback : callback//,				//搜索按钮点击后回调
		});
		//搜索回调函数
		function callback(data){
			jQuery("#module_list_table").jqGrid('setGridParam', {
				url : "${ctx}/${frameworkPath}/module/list?sort=MODULE_ORDER&&dir=asc",
				mtype : "POST",
				postData:data //传递的数据
			}).trigger("reloadGrid");
		}


		//调整以适应页面大小  其中 $(".page-content") 为jqgrid的父级容器
		$(window).off('resize.jqGrid').on('resize.jqGrid', function () {
			setTimeout(function(){
				$(_grid_id).jqGrid("setGridWidth",$(".page-content").width());
				$(".ui-jqgrid-bdiv").width($(".page-content").width()+1);
			},50);
		});
		jQuery(_grid_id).jqGrid({
			mtype : "POST",
			url: "${ctx}/${frameworkPath}/module/list?sort=MODULE_ORDER&&dir=asc",
			colNames:['编号','模块名称','创建者','创建时间','排序字段','操作'],
			colModel:[
				{name:'id',index:'id', width:0,  editable: true,  hidden:true},
				{name:'name',index:'name', width:0,  editable: true},
				{name:'creator',index:'creator', width:60,  editable: true},
				{name:'created',index:'created', width:60,  editable: true,align:'center'},
				{name:'order',index:'order', width:30,  editable: true,align:'center'},
				{name:'action',index:'', width:100, fixed:false, sortable:false,align:'center', formatter:
						function(cellvalue, options, rowObject) {
							var s='<div class=" action-buttons">'
							s=s+  '<a class="blue my-tooltip-link tooltip-primary" title="编辑" style="cursor:pointer" ><i class="ace-icon fa fa-pencil bigger-130 " onclick="editrow(\''+rowObject.id+'\')"></i></a>'    ;
							s=s+  '<a class="red my-tooltip-link tooltip-primary" title="删除" style="cursor:pointer"><i class="ace-icon fa fa-trash-o bigger-130"  onclick="deleterows(\''+rowObject.id+'\')"></i></a>' ;
							return s+'</div>';}
				}
			],
			pager : _pager_id, //分页信息 放置的位置
			page : lui.pageNum(_grid_id)
		});
		//自定义工具栏 =============BEGIN======================//
		jQuery(_grid_id)
				.jqGrid('navGrid',_pager_id)
				.navButtonAdd( _pager_id,{
					title : "新增",//按钮悬浮提示
					//iconTitle : "新增",//图标下面显示（不填的话默认为title里面的值）
					buttonicon : "ace-icon fa fa-plus-circle purple",
					onClickButton: function(){
						lui.open({
							title: '新增模块',
							content: "${ctx}/${frameworkPath}/module/create",
							area: ['600px', '300px'],
							yes: function(index, layero){
								var iframeWin = $(layero).find("iframe")[0].contentWindow;
								var retObj = iframeWin.formValid();
								if(retObj.text){
									lui.info(retObj.text);
									if(retObj.state){
										layer.close(index);
										jQuery(_grid_id).trigger("reloadGrid");
									}
								}
							}
						});
					}
				})
				.navButtonAdd( _pager_id,{
					title : "编辑",
					buttonicon : "ace-icon fa fa-pencil blue",
					onClickButton :  editrows
				})
				.navButtonAdd( _pager_id,{
					title : "删除",
					buttonicon : "ace-icon fa fa-trash-o red",
					onClickButton : deleteRows
				})
				.navButtonAdd( _pager_id,{
					title : "刷新",
					buttonicon : "ace-icon fa fa-refresh orange",
					onClickButton : function(){
						//callback();
						jQuery(_grid_id).trigger("reloadGrid");
					}
				})

	});

	//编辑数据
	function editrow(id){
		lui.open({
			title: '编辑模块',
			content: "${ctx}/${frameworkPath}/module/edit?id="+id,
			area: ['600px', '300px'],
			yes: function(index, layero){
				var iframeWin = $(layero).find("iframe")[0].contentWindow;
				var retObj = iframeWin.formValid();
				if(retObj.text){
					lui.info(retObj.text);
					if(retObj.state){
						layer.close(index);
						jQuery(_grid_id).trigger("reloadGrid");
					}
				}
			}
		});
	}

	function editrows(){
		var ids =  $("#module_list_table").jqGrid('getGridParam','selarrrow');
		if(ids.length<1){
			lui.warn('至少选择一行数据');
			return;
		}
		else if(ids.length>1){
			lui.warn("最多选择一行数据");
			return;
		}
		lui.open({
			title: '编辑模块',
			content: "${ctx}/${frameworkPath}/module/edit?id="+ids[0],
			area: ['600px', '300px'],
			yes: function(index, layero){
				var iframeWin = $(layero).find("iframe")[0].contentWindow;
				var retObj = iframeWin.formValid();
				if(retObj.text){
					lui.info(retObj.text);
					if(retObj.state){
						layer.close(index);
						jQuery(_grid_id).trigger("reloadGrid");
					}
				}
			}
		});
	}

	//删除
	function deleterows(id){
		lui.confirm('确实要删除吗？',function(){
			var idArray = new Array();
			idArray.push(id);
			$.ajax({
				type:'POST',
				url:'${ctx}/${frameworkPath}/module/delete',
				traditional:true,
				dataType:'json',
				data:{'ids':idArray},
				success:function(data){
					if(data.success){
						lui.success('删除成功');
						jQuery(_grid_id).trigger("reloadGrid");
					}
					else{
						lui.fail('删除失败');
					}
				},
				error: function(XmlHttpRequest, textStatus, errorThrown){
					lui.fail('删除失败');
				}
			});
		},function(){});
	}

	function deleteRows(){
		var ids =  $("#module_list_table").jqGrid('getGridParam','selarrrow');
		if(ids.length<1){
			bootbox.alert({title:'提示消息',message:'至少选择一行数据'});
			return;
		}
		lui.confirm('确实要删除吗？',function(){
			var idArray = new Array();
			for(var i=0; i<ids.length; i++){
				idArray.push(ids[i]);
			}
			$.ajax({
				type:'POST',
				url:'${ctx}/${frameworkPath}/module/delete',
				traditional:true,
				dataType:'json',
				data:{'ids':idArray},
				success:function(data){
					if(data.success){
						lui.success('删除成功');
						jQuery(_grid_id).trigger("reloadGrid");
					}
					else{
						lui.fail('删除失败');
					}
				},
				error: function(XmlHttpRequest, textStatus, errorThrown){
					lui.fail('删除失败');
				}
			});
		},function(){});
	}
</script>